// pages/components/mytree/mytree.js
Component({
	properties: {
		model: Array,
		treeType: {
			type:Number,
			value:1
		},
		treeRank:{
			type:Number,
			value:1
		}
	},
	data: {
		indexShow: [], //展开项
	},

	methods: {
		toggle: function(item) {
			let _this = this
			let cacheArr = []
			_this.data.indexShow.forEach((e, i) => {
				if (item.currentTarget.dataset.index == i) {
					cacheArr.push(!e)
				} else {
					cacheArr.push(e)
				}
			})
			_this.setData({
				indexShow: cacheArr
			})
		},
	},

	ready: function(e) {
		let cacheArr = [];
		let _this = this
		this.data.model.forEach((e, i) => {
			switch (_this.data.treeType) {
				case 0: //所有关闭
					cacheArr.push(false)
					break;
				case 1://第一个第一级展开
					cacheArr.push((_this.data.treeRank == 1 && i==0) ? true : false);
					break;
				case 2://第一组所有展开
					cacheArr.push(_this.data.treeRank == 1 ? true : false);
					break;
				case 3: //递归所有第一级展开 
					cacheArr.push(i == 0 ? true : false)
					break;
				case 4: //展开所有菜单 
					cacheArr.push(true)
					break;
				default:
					cacheArr.push(false)
			}

		})
		this.setData({
			indexShow: cacheArr,
			// treeRank:_this.data.treeRank
		});
		
	},
})
